﻿<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.zaofan.bean.Lable"%>
<%@page import="com.zaofan.cache.CacheManage"%>
<%@page import="com.zaofan.constant.LableConstant"%>
<%@page import="com.zaofan.bean.Admin"%>
<%@page import="com.zaofan.bean.AdminType"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
	String contextPath = request.getContextPath();
	Admin admin = (Admin)session.getAttribute("admin");
	if(admin == null){
		response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
		return;
		}
	if(admin.getType() != AdminType.admin.ordinal() &&  admin.getType() != 4){
		response.sendRedirect(contextPath + "/login.jsp?state=" + "session-invalid");
		return;
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>退款订单列表</title>
<link href="<%=contextPath%>/admin/css/base.css" rel="stylesheet" />
<link href="<%=contextPath%>/admin/assets/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome.min.css" />
<!--[if IE 7]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/font-awesome-ie7.min.css" />
<![endif]-->
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-rtl.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-skins.min.css" />
<!--[if lte IE 8]>
	<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/ace-ie.min.css" />
<![endif]-->
<script src="<%=contextPath%>/admin/assets/js/ace-extra.min.js"></script>
<!--[if lt IE 9]>
	<script src="<%=contextPath%>/admin/assets/js/html5shiv.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/jquery-ui-1.10.3.custom.min.css" />
<link rel="stylesheet" href="<%=contextPath%>/admin/assets/css/chosen.css" />
<link rel="stylesheet"
	href="<%=contextPath%>/admin/assets/css/daterangepicker.css" />
<script type="text/javascript">  
       var contextPath='<%=contextPath%>';
</script>
</head>
<body style="background-color: #fff;">
						<%
								application.setAttribute("special", CacheManage.specialShop);
								pageContext.setAttribute("admin", admin);
								application.setAttribute("expressType", CacheManage.lables.get(LableConstant.lable_express_type));
							%>
	<div class="page-content">
		<div id="adEditBox"
			 style="display: none; z-index: 99; width: 600px; position: fixed; left: 15%; top: 5%; border: 1px solid #ccc; border-radius: 4px !important;">
			<div class="arrow"></div>
			<div class="popover-inner" style="">
				<h3 class="popover-title" >订单编辑</h3>
				<div class="popover-content"  style="background-color: #F5F5F5;">
					<form class="form-horizontal" style="padding-top: 10px;"
						  method="get" id="adForm" enctype="multipart/form-data">
						<input type="hidden" id="id" name="id" value="" />
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">送货日期：</label>
							<div class="col-sm-9">
								<input class="form-control" name="sendDate" id="sendDate"/>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">送货时间</label>
							<div class="col-sm-9">
								<input class="form-control" name="sendTime" id="sendTime"/>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>
						<div class="form-group">
							<label  class="col-sm-2 control-label">收货人</label>
							<div class="col-sm-9">
								<input class="form-control" name="consignee" id="consignee"/>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>

						<div class="form-group">
							<label  class="col-sm-2 control-label">收货大楼：</label>
							<div class="col-sm-9">
								<input class="form-control" name="builderName" id="builderName"></input>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>

						<div class="form-group">
							<label for="" class="col-sm-2 control-label">收货楼层：</label>
							<div class="col-sm-9">
								<input class="form-control" name="floorNo" id="floorNo"></input>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>

						<div class="form-group">
							<label for="" class="col-sm-2 control-label">收货人电话：</label>
							<div class="col-sm-9">
								<input class="form-control" name="userMobile" id="userMobile"></input>
							</div>
							<span class="input_tip" style="line-height: 30px;">*</span>
						</div>
					</form>
				</div>
				<div class="popover-footer"
					 style="background-color: #F5F5F5; overflow: hidden; text-align: center;">
					<button type="button" class="btn btn-primary"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="cancel">
						<i class="icon-ok"></i>取消
					</button>
					<button type="button" class="btn btn-danger"
							style="padding: 0px; margin: 0px 5px 5px 0px;" id="save">
						<i class="icon-edit"></i>保存
					</button>

				</div>
			</div>
		</div>
		<div class="row" style="height: 100%">
			<div class="col-xs-12">
				<div class="panel panel-default">
				  <div class="panel-heading">订单查找</div>
				  <div class="panel-body">
				  		<form class="form-inline">

				  				<label for="key">城市:</label>
				  				<select id="citys" style="width:150px;">
									<%if(admin.getCityId()==0){%>
				  					<option value="0">全部</option>
									<%}%>

				  				</select>&nbsp;&nbsp;

								<input type="hidden" value="" id="areaId"  />
								<input type="hidden" value="" id="builderId"  />
								<input type="hidden" value="" id="shopId"  />
								<input type="hidden" value="" id="property"  />
								<input type="hidden" value="" id="state"  />
								<input type="hidden" value="" id="accountMobile"  />
								<input type="hidden" value="" id="orderNo"  />
								<input type="hidden" value="" id="expressLableId"  />
								<input type="hidden" value="" id="orderTime"  />
								<label for="key">订单状态:</label>
								<select id="states" style="width:150px;" >
									<option value="3">待退款</option>
									<option value="4">已退款</option>

				  				</select>&nbsp;&nbsp;
								<input type="hidden" value="" id="key"  />
								<label for="key">号码：</label>
								<input id="mobile" class="form-control" value="" style="width:150px;" />&nbsp;&nbsp;
								<label for="key">收货人号码：</label>
								<input id="phone" class="form-control" value="" style="width:150px;" />&nbsp;&nbsp;
								<%--<button type="button" class="btn btn-primary btn-sm" id="find">查找</button>--%>
								<br/><br/>
								<label for="key">订单号：</label>
								<input id="orderNoValue" class="form-control" value="" style="width:150px;" />&nbsp;&nbsp;
								<button type="button" class="btn btn-primary btn-sm" id="findorder">查找</button>
								<%--<button type="button" class="btn btn-primary btn-sm" id="print">打印</button>--%>
						</form>
				  </div>
				</div>
			</div>
			<div class="col-xs-12">
			<style>
				.table-responsive table th tr{text-align: center;}
			</style>
				<div class="table-responsive">
					
					<input type="hidden" value="1" id="start" />
					<table id="sample-table-2"
						class="table table-striped table-bordered table-hover">
						<thead>
							<tr>
								<th style="text-align: center;">订单号</th>
								<th style="text-align: center;">订单ID</th>
								<th style="text-align: center;">手机号</th>
								<th style="text-align: center;" class="orderTimeOrder"><input type="hidden" value="desc" />状态</th>
								<th style="text-align: center;" class="totalPriceOrder"><input type="hidden" value="desc" />支付金额</th>

								<th style="text-align: center;">支付方式</th>
								<%--<th style="text-align: center;">收货信息</th>
								<th style="text-align: center;">交易号</th>

								<th style="text-align: center;">退款原因</th>--%>
								<%--
								<th style="text-align: center;">操作 <button onclick="refund_pay()">批量退款</button></th>
								--%>
							</tr>
                            </thead>
                            <tbody id="data-list"  style="text-align: center;">
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- /.col -->
		</div>
		<!-- /.row -->
		<div class="row">
			<div class="col-sm-6">
				<div id="sample-table-2_info" class="dataTables_info">
					当前    <span id="current">  </span> 到  <span id="page"></span> 总共 <span
						id="total"></span> 条
				</div>
			</div>
			<div class="col-sm-6">
				<div class="dataTables_paginate paging_bootstrap">
					<ul class="pagination pagination-sm" id="page-list">
					</ul>
				</div>
			</div>
		</div>
	</div>
	<div id="loading"
		style="width: 32px; height: 32px; position: fixed; left: 40%; top: 40%; display: none;">
		<img src="<%=contextPath%>/admin/assets/css/images/loading.gif"
			width="32" height="32" />
	</div>
	<div class="popover"
		style="z-index: 9999; width: 150px; position: fixed; left: 40%; top: 40%;">
		<div class="arrow"></div>
		<div class="popover-inner">
			<h3 class="popover-title">操作提示</h3>
			<div class="popover-content" id="popover-content">
				<p>操作成功</p>
			</div>
		</div>
	</div>
	<style>
		#detailsBox{border:1px solid #999;border-bottom:none;}
		#detailsBox thead tr th{width:20%;padding:10px;}
		#detailsBox thead tr{border-bottom:1px solid #999;}
		#detail-list tr{border-bottom:1px solid #999;}
		
	</style>
	<div id="detailsBox" style="width: 900px;position: absolute;display:none; ">
		<table id="sample-table-2"
			class=""  style="background-color:#f5f5f5;width:100%">
			<thead  style="background-color:#f5f5f5;width:100%">
				<tr>
					<th style="text-align: center;">产品名</th>
					<th style="text-align: center;">产品图片</th>
					<th style="text-align: center;">产品价格</th>
					<th style="text-align: center;">产品数量</th>
					<th style="text-align: center;">商铺信息</th>
				</tr>
			</thead>
			<tbody id="detail-list" style="text-align: center;background-color:#f5f5f5">
			</tbody>
		</table>
	</div>
	
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"/script>");
	</script>
	<script type="text/javascript">
		window.jQuery
				|| document
						.write("<script src='<%=contextPath%>/admin/assets/js/jquery-2.0.3.min.js'>"
								+ "<"+"script>");
	</script>
	
	<!--[if IE]>
		<script type="text/javascript">
			window.jQuery || document.write("<script src='<%=contextPath%>/admin/assets/js/jquery-1.10.2.min.js'>"+"<"+"script>");
		</script>
	<![endif]-->
	<script type="text/javascript">
		if ("ontouchend" in document)
			document
					.write("<script src='<%=contextPath%>/admin/assets/js/jquery.mobile.custom.min.js'>"
							+ "<"+"script>");
	</script>
	<script src="<%=contextPath%>/admin/assets/js/bootstrap.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/typeahead-bs2.min.js"></script>

	<!--[if lte IE 8]>
		  <script src="assets/js/excanvas.min.js"></script>
	<![endif]-->
	<script src="<%=contextPath%>/admin/assets/js/jquery-ui-1.10.3.custom.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.ui.touch-punch.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.slimscroll.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.easy-pie-chart.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.sparkline.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace-elements.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/ace.min.js"></script>
	<script src="<%=contextPath%>/admin/js/common.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery-form.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/bootstrap-datepicker.min.js"></script>
	<script src="<%=contextPath%>/admin/assets/js/date-time/moment.min.js"></script>
	<script	src="<%=contextPath%>/admin/assets/js/date-time/daterangepicker.min.js"></script>
	
	<script type="text/javascript">
		$("#citys").change(function(){
			getData(1);
		});
		$("#states").change(function(){
			getData(1);
		});

	var time = null;
	var order = " by orderTime desc,totalPrice desc";

    $.ajax({
        url : contextPath + '/city',
        type : "POST",
        dataType : 'json',
        data : {
            action : 'list',
            order:' by sort asc'
        },
        success : function(rs, textStatus, jqXHR) {
            if (rs.success) {
                var data = rs.data;
                var options = "";
                for(var i = 0 ; i < data.length ; i++){
                    options += '<option value="'+data[i].id+ '">' + data[i].cityName + '</option>';
                }
                $("#citys").append(options);
                $("#citys").val(-1);
                $.ajax({
                    url : contextPath + '/area',
                    type : "POST",
                    dataType : 'json',
                    data : {
                        action : 'list',
                        cityId:1,
                        order:' by sort asc'
                    },
                    success : function(rs, textStatus, jqXHR) {
                        if (rs.success) {
                            var data = rs.data;
                            var options = '<option value="-1" selected="selected">全部</option>';
                            for(var i = 0 ; i < data.length ; i++){
                                options += '<option value="'+data[i].id+ '">' + data[i].areaName + '</option>';
                            }

                        } else {
                            showMessage("获取数据失败,请稍后再试");
                        }
                        $("#loading").hide();
                    },
                    error : function() {
                        $("#loading").hide();
                        showMessage("请稍后再试");
                    }
                });
            } else {
                showMessage("获取数据失败,请稍后再试");
            }
            $("#loading").hide();

        },
        error : function() {
            $("#loading").hide();
            showMessage("请稍后再试");
        }
    });


    function getOrder(val){

			getData(1);
		}

		$(function(){
				init();
		});
		function init() {
			setTimeout(getData(1), 1000);
		}


		function getData(start) {
            var ordersNO="";

			var payState="3";//待退款
			var city = <%=admin.getCityId()%> ;
			var mobiles="";
			var phone="";
			if($("#citys").val() == -1 || $("#citys").val() == ""|| $("#citys").val() == null){
				city = <%=admin.getCityId()%>;
			}else{
				city =  $("#citys").val();
			}

			if($("#mobile").val() != ""){
				mobiles =$("#mobile").val();}
			if($("#phone").val() != ""){
				phone =$("#phone").val();}
			if( $("#states").val() != ""&& $("#states").val() != null){
				payState=$("#states").val();
			}

			if($("#orderNoValue").val() != ""&&$("#orderNoValue").val() != null){
				ordersNO = $("#orderNoValue").val();

			}



			    $("#loading").show();
				$.ajax({
					url :  contextPath + '/find_refund',                             //路径
					type : "POST",
					dataType : 'json',
					data : {
						action : 'list',
						more:  'loading',
                        cityId:  city,
						mobile: mobiles,
						phone:phone,
						payState:payState,
						orderNo:ordersNO,
			            todo:start,

						begin : (start - 1) * 20,
						end : 20,
						order:order
					},
					success : function(rs, textStatus, jqXHR) {
						if (rs.success) {
							var data = rs.data;
							var total = rs.total;
							var dataList = $("#data-list");
							dataList.empty();
							$("#total").text(total);
							$("#current").text((start - 1) * 20 + 1);
							if (data.length > 0) {
								$("#page").text(
										(start - 1) * 20 + data.length);
								parseData(data, total, start);
							} else {
								showMessage("无数据");
							}
						} else {
							showMessage("获取数据失败,请稍后再试");
						}
						$("#loading").hide();

					},
					error : function() {
						$("#loading").hide();
						showMessage("请稍后再试");
					}
			    });
		}




		$("#print").click(function(){
			var property = "";
			if($("#citys").val() == -1 || $("#citys").val() == ""|| $("#citys").val() == null){
				property = "";
			}else{
				property = "cityId=" + $("#citys").val();
			}
			if($("#areaId").val() != -1 && $("#areaId").val() != ""){
				if(property == ""){
					property = "areaId=" + $("#areaId").val();
				} else {
					property = "&areaId=" + $("#areaId").val();
				}
			}
			if($("#builderId").val() != -1 && $("#builderId").val() != ""){
				if(property == ""){
					property = "builderId=" + $("#builderId").val();
				}else{
					property += "&builderId=" + $("#builderId").val();
				}
			}
			if($("#shopId").val() != -1 && $("#shopId").val() != ""){
				if(property == ""){
					property = "shopId=" + $("#shopId").val();
				}else{
					property += "&shopId=" + $("#shopId").val();
				}
			}
			if($("#state").val() != -1 && $("#state").val() != ""){
				if(property == ""){
					property = "state=in" + $("#state").val();
				}else{
					property += "&state=in" + $("#state").val();
				}
			}
			if($("#accountMobile").val() != ""){
				if(property == ""){
					property = "accountMobile=" + $("#accountMobile").val();
				}else{
					property += "&accountMobile=" + $("#accountMobile").val();
				}
			}
			if($("#orderNo").val() != ""){
				if(property == ""){
					property = "orderNo=" + $("#orderNo").val();
				}else{
					property += "&orderNo=" + $("#orderNo").val();
				}
			}
			if($("#orderTime").val() != ""){
				if(property == ""){
					property = "orderTime=" + $("#orderTime").val();
				}else{
					property += "&orderTime=" + $("#orderTime").val();
				}
			}

			if($("#expressLableId").val() != -1 && $("#expressLableId").val() != ""){
				if(property == ""){
					property = "expressLableId=" + $("#expressLableId").val();
				}else{
					property += "&expressLableId=" + $("#expressLableId").val();
				}
			}
			window.location.href =  contextPath + '/order?action=export_list&order= by orderTime desc' + (property == "" ? "" : "&" + property);
		});

		function parseData(data, total, start) {
			var dataList = $("#data-list");
			var tr = "";
			for (var i = 0; i < data.length; i++) {

				tr += '<tr>';
				tr += '<td><a href="javascript:void(0)"  class="showDetai" orderId='+data[i].id+' detailInfo="">'+data[i].orderNo+'</a></td>';
				tr += '<td>'+data[i].id+'</td>';
				tr += '<td>'+data[i].accountMobile+'</td>';


				if(data[i].payState==3){
					tr += '<td>待退款</td>';
				}
				else if(data[i].payState==4){
					tr += '<td>已退款</td>';
				}
				tr += '<td>'+data[i].payPrice +'</td>';

				tr += '<td>'+data[i].payType+'</td>';

				/*tr += '<td>操作人:'+data[i].confirmUser+'<br/>'+'确认日期:'+data[i].confirmDate+'</td>';
				tr += '<td>'+data[i].tradeNo+'</td>';
                tr += '<td>'+data[i].refundReason+'</td>';
				tr += '<td><input type="hidden" value="'+data[i].id+'" class="orderId"/><a target="_blank" href="'+contextPath + '/order?action=print_order&orderId=' + data[i].id +' ">打印</a>';
				 tr += 	'<a onclick= "editorder('+data[i].id+')">查看详情</a>' ;
				tr +='<a onclick= "backorder('+data[i].orderNo+')">退款</a>';
                 tr +='<input name="'+data[i].orderNo+'"id="checkbox'+i+'" type="checkbox" />'


				tr+= "</td>"
				tr += '</tr>';*/
			}
			dataList.append(tr);


//			$(".showDetai").hover(function(event){
//				clearTimeout(time);
//				var pointX = event.pageX;
//				//这里可以得到鼠标Y坐标
//				var pointY = event.pageY;
//				console.log("x = " + pointX + ",y = " + pointY);
//				$("#detailsBox").css("top",(pointY+20)+"px");
//				$("#detailsBox").css("left",(pointX+20)+"px");
//				var box = $(this);
//				var id = $(this).attr("orderId");
//				var detailInfo = $(this).attr("detailInfo");
//				if(detailInfo != ""){
//					$("#detail-list").empty();
//					$("#detail-list").append(detailInfo);
//					$("#detailsBox").show();
//					return;
//				}
//				$("#loading").show();
//				$.ajax({
//					url : contextPath + '/order',
//					type : "POST",
//					dataType : 'json',
//					data : {
//						action : 'detail',
//						id:id
//					},
//					success : function(rs, textStatus, jqXHR) {
//						if (rs.success) {
//							var data = rs.data;
//							var tr = "";
//							for(var i = 0 ; i < data.length ; i++){
//								tr += '<tr>';
//								tr += '<td>'+data[i].productName+'</a></td>';
//								tr += '<td><img src="' + contextPath + data[i].productImage+'" width="40px" height="40" /></td>';
//								tr += '<td>'+data[i].productPrice+'</td>';
//								tr += '<td>'+data[i].productCount+'</td>';
//								tr += '<td>'+data[i].shopName+'</td>';
//								tr += '</tr>';
//							}
//							box.attr("detailInfo",tr)
//							$("#detail-list").empty();
//							$("#detail-list").append(tr);
//							$("#detailsBox").show();
//						} else {
//							showMessage("获取数据失败,请稍后再试");
//						}
//						$("#loading").hide();
//					},
//					error : function() {
//						$("#loading").hide();
//						showMessage("请稍后再试");
//					}
//				});

//			},function(){
//				time = setTimeout( function(){
//					$("#detailsBox").hide();
//				} , 1000);
//			});

			var pageList = $("#page-list");
			pageList.empty();
			pageList.append(getPageInfo20(start, total));
			$("html,body").animate({scrollTop:0},200);
	}

		$("#detailsBox").hover(function(){
			clearTimeout(time);
		},function(){
			clearTimeout(time);
			$("#detailsBox").hide();
		});

		$("#find").click(function(){
			$("#accountMobile").val($("#mobile").val());
			getData(1);

		});
	$("#findorder").click(function(){

		getData("order");

	});
		$("#findOrder").click(function(){
			$("#orderNo").val($("#orderNoValue").val());
			getData(1);

		});

		$(".orderTimeOrder").bind("click",function(){
			var des = $(this).find("input").val();
			if(des == "desc"){
				$(this).find("input").val("asc");
				order = " by orderTime asc";
			}else{
				$(this).find("input").val("desc")
				order = " by orderTime desc";
			}

			des = $(".totalPriceOrder").find("input").val();
			if(des == "desc"){
				order += " ,totalPrice desc";
			}else{
				order = " ,totalPrice asc";
			}

			getData(1);
		});
		$(".totalPriceOrder").bind("click",function(){
			var des = $(this).find("input").val();
			if(des == "desc"){
				$(this).find("input").val("asc");
				order = " by totalPrice asc";
			}else{
				$(this).find("input").val("desc")
				order = " by totalPrice desc";
			}
			des = $(".orderTimeOrder").find("input").val();
			if(des == "asc"){
				order = " by orderTime asc";
			}else{
				order = " by orderTime desc";
			}
			getData(1);
		});

	function editorder(orderid){

		$("#id").val(orderid);
		var action='/order?action=get&id='+orderid;

		$.get(action,function (result) {
			result = JSON.parse(result);
			var data = result.data ;
			console.log(result);
			$("#id").val(data.id);
			$("#sendDate").val(data.sendDate);
			$("#sendTime").val(data.sendTime);
			$("#consignee").val(data.consignee);
			$("#builderName").val(data.builderName);
			$("#userMobile").val(data.userMobile);
			$("#floorNo").val(data.floorNo);
			$("#adEditBox").show();
		})


	}

	$("#cancel").bind("click", function () {
		$("#adEditBox").hide();
		$("#id").val("");
		$("#sendDate").val("");
		$("#sendTime").val("");
		$("#consignee").val("");
		$("#builderName").val("");
		$("#userMobile").val("");
		$("#floorNo").val("");
	});

	$("#save").bind("click", function () {

		var action='/order?action=order_edit';


		if ($("#id").val() == "") {
			showMessage("id错误,请联系管理员");
			return;
		}
		if ($("#sendDate").val() == "") {
			showMessage("请输入送货日期!!!");
			return;
		}
		if ($("#sendTime").val() == "") {
			showMessage("请输入送货时间!!!");
			return;
		}
		if ($("#consignee").val() == "") {
			showMessage("请输入收货人名称!!!");
			return;
		}
		if ($("#floorNo").val() == "") {
			showMessage("请输入楼层!!!");
			return;
		}
		if ($("#builderName").val() == "") {
			showMessage("请输入送达楼宇!!!");
			return;
		}
		if ($("#userMobile").val() == "") {
			showMessage("请输入收货人手机!!!");
			return;
		}

		$("#consignee").val(encodeURI($("#consignee").val()));
		$("#builderName").val(encodeURI($("#builderName").val()));
		$("#floorNo").val(encodeURI($("#floorNo").val()));



		$("#loading").show();
		$("#adForm").ajaxSubmit({
			type: "GET",
			url: contextPath + action,
			dataType: 'json',
			success: function (data) {
				if (data.success) {
					showMessage(data.msg);

					$("#adEditBox").hide();
					$("#id").val("");
					$("#sendDate").val("");
					$("#sendTime").val("");
					$("#consignee").val("");
					$("#builderName").val("");
					$("#userMobile").val("");
					$("#floorNo").val("");
					setTimeout(function () {
						getData(1);
					}, 2000);
				} else {
					showMessage(data.msg);
				}
				$("#loading").hide();
			},
			error: function (msg) {
				$("#loading").hide();
				showMessage("操作失败");
			}
		});
	});
	//单个退款
	function backorder(orderNo){

        var datail=orderNo;
		datail = "#"+datail;
		var s = 1;
        window.focus();
		$.ajax({
			url : contextPath + '/find_refund',
			type : "POST",
			dataType : 'json',
			data : {
				action : 'list',
				more  : 'refund',
				num   :   s,
				datails  : datail,
			},
			success : function(rs, textStatus, jqXHR) {
				if (rs.success) {

					var msg=rs.msg;
					var flag=rs.flag;

					if(flag ==1){

						var url=contextPath+msg;
						var newwindow=window.open("about:blank");
						newwindow.location.href=url;
						newwindow.focus();
					}else {

						showMessage("退款完成!")
					}

				} else {
					showMessage("获取数据失败,请稍后再试");
				}
				$("#loading").hide();
			},
			error : function() {
				$("#loading").hide();
				showMessage("请稍后再试");
			}
		});



	}



	function refund_pay() {

        var i= document.getElementById("data-list").rows.length;
	  //	alert(i);
		var datail="";
		var s = 0;
       //存放退款的数据
		for(var j=0;j<i;j++){
			var checkbox = document.getElementById("checkbox"+j);
		 if(checkbox.checked) {
            datail =datail+"#"+checkbox.name ;

			  s=s+1;
		 }


     }
		//var newwindow=window.open("about:blank");
		  window.focus();
     $.ajax({
			url : contextPath + '/find_refund',
			type : "POST",
			dataType : 'json',
			data : {
				action : 'list',
				more  : 'refund',
				num   :   s,
				datails  : datail,
			},
			success : function(rs, textStatus, jqXHR) {
				if (rs.success) {

                    var msg=rs.msg;
                    var flag=rs.flag;

					if(flag==1){

						var url=contextPath+msg;
					    var newwindow=window.open("about:blank");
					    newwindow.location.href=url;
					    newwindow.focus();
					}

				} else {
					showMessage("获取数据失败,请稍后再试");
				}
				$("#loading").hide();
			},
			error : function() {
				$("#loading").hide();
				showMessage("请稍后再试");
			}
		});



	}
	</script>
</body>
</html>